<?php 
if(empty($this->logged_users)) {
?>
	<div class="information">Aucun utilisateur en attente dans cette section</div>
<?php
} else {
	?>
	<form id="logs_form" action="<?php echo $this->url(array('module' => 'backend', 'controller' => 'manage', 'action' => 'logsapply'), null, true); ?>" method="post">
	<?php foreach($this->logged_users AS $echelon => $s) { ?>
		<div class="structure_name">
			<h4><?php echo $echelon; ?></h4>
		</div>	

		<table id="waiting_tab">
			<tr>
				<th>Date de la demande</th>
				<th>Fonction</th>
				<th>Civilit&eacute;</th>
				<th>Nom</th>
				<?php if($this->action == "archivated"){?>
				<th>Statut</th>
				<th>Modifier</th>
				<?php }else{ } ?>
				<th>Status</th>
				<th>Action</th>
			</tr>

			<?php foreach($s['user'] AS $u) {
				// Change function format
				$function = preg_replace('/___/', ' ', $u['function']);
				$function = preg_replace('/_/', ' ', $u['function']);	// For Animateur_BDI
				?>
				<tr>
					<td><?php echo $u['date']; ?></td>
					<td><?php echo $function; ?></td>
					<td><?php echo $u['extra']['civility']; ?></td>
					<td style="cursor: pointer;" onclick="javascript: window.open('<?php echo $this->url(array('module' => 'backend', 'controller' => 'user', 'action' => 'set', 'id' => $u['id_user']), null, true);?>', 'Fiche_utilisateur', 'height=800, width=600, left=50%, toolbar=no, menubar=no, location=no, resizable=no, scrollbars=yes, status=no')" title="modifier l'utilisateur"><?php echo $u['lastname'].' '.$u['firstname']; ?></td>
					<td>
						<?php if($u['status'] == 'accepted') { ?>
							Accepté
						<?php } else if($u['status'] == 'rejected') { ?>
							Rejeté
						<?php } ?>
							
					</td>
					<td>
						<?php if($u['status'] == 'accepted') { ?>
							<label for="<?php echo $u['id_user'].'_'.$s['structure']['id'].'_'.$u['icf']; ?>">Rejeter : </label>
							<input type="checkbox" id="<?php echo $u['id_user'].'_'.$s['structure']['id'].'_'.$u['icf']; ?>" name="logs_reject[]" value="rejected_<?php echo $u['id_user'].'_'.$s['structure']['id'].'_'.$u['icf']; ?>" />
						<?php } else if($u['status'] == 'rejected') { ?>
							<label for="<?php echo $u['id_user'].'_'.$s['structure']['id'].'_'.$u['icf']; ?>">Accepter : </label>
							<input type="checkbox" id="<?php echo $u['id_user'].'_'.$s['structure']['id'].'_'.$u['icf']; ?>" name="logs_accept[]" value="accepted_<?php echo $u['id_user'].'_'.$s['structure']['id'].'_'.$u['icf']; ?>" />
						<?php } ?>
					</td>
				</tr>
			<?php } ?>
		</table>
		<input type="submit" id="logs_send" class="logs_submit" name="manage_send" value="Confirmer" />
	<?php
	}
	?>
	</form>
<?php
}
?>
<div id="logs_mess" style="display: none;"></div>

<script type="text/javascript">
	$('.logs_submit').click(function(e) {
		
		$('#logs_mess').html('<img src="<?php echo $this->baseUrl; ?>/images/icones/loading.gif" alt="" />');
		$('#logs_mess').fadeIn();
		
		$('#logs_form').ajaxSubmit({
			dataType: 'json',
			success: function(e) {
				if(e.return != 'OK') {
					$('#logs_mess').html('<div class="error">'+e.return+'</div>');
				
				} else {
					$('#logs_mess').html('<div class="information">Traitement effectué</div>');
					$('#logs_form').fadeOut();
					setTimeout('location.reload()', 1500);
				}
				return false;
			}
		});
		
		return false;
		
	});
</script>
